﻿using System.IO;

namespace Tasks
{
    public class ChangeNamespaceTask
    {

        public static void Execute(string source, string newNamespace)
        {
            var exclude = new[]
                              {
                                  "Content", "_References", "Properties", 
                                  "*.suo", "*.sln", "*.dll", "*.js", "*.css", 
                                  "*.jpg", "*.png", "*.gif", "*.csproj", 
                                  "*.csproj.user"
                              };
            foreach (var file in Utilities.GetFiles(source, exclude, null))
            {
                var content = File.ReadAllText(file.FullName);

                content = content.Replace("namespace BigfootMVC", "namespace " + newNamespace);
                content = content.Replace("using BigfootMVC", "using " + newNamespace);

                File.WriteAllText(file.FullName, content);
            }

            var projFilePath = Path.Combine(source, "BigfootMVC.csproj");
            var proj = File.ReadAllText(projFilePath);
            proj = proj.Replace("<RootNamespace>BigfootMVC</RootNamespace>","<RootNamespace>"+ newNamespace +"</RootNamespace>");
            proj = proj.Replace("<AssemblyName>BigfootMVC</AssemblyName>","<AssemblyName>"+ newNamespace +"</AssemblyName>");
            File.WriteAllText(projFilePath, proj);
        }

    }
}
